#include "camera.h"

c_frustum::c_frustum(const float fov, const float aspect, const float near_plane, const float far_plane)
    : m_fov(fov)
    , m_aspect(aspect)
    , m_near_plane(near_plane)
    , m_far_plane(far_plane)
{
    m_mat_proj = get_projection_matrix(); 
}

c_matrix4x4 c_frustum::get_projection_matrix() const
{
    c_matrix4x4 mat_proj = make_perspective_proj_matrix(m_fov, m_aspect, m_near_plane, m_far_plane); 
    return mat_proj;
}


//////////////////////////////////////////////////////////////////////////

c_camera::c_camera(c_scene *scene_mgr, const std::string& name, const c_vector3& postion, const c_vector3& lookat, const c_vector3& up, const frustum_ptr& frustum)
    : c_scene_node(scene_mgr, name)
    , m_is_active(false)
	, m_frustum(frustum)
{
	SetViewParams((D3DXVECTOR3*)&postion, (D3DXVECTOR3*)&lookat); 
	if (frustum)
		SetProjParams(frustum->m_fov, frustum->m_aspect, frustum->m_near_plane, frustum->m_far_plane); 
}

c_matrix4x4 c_camera::get_view() const
{
	const D3DXMATRIX *view_mat = GetViewMatrix();
	return c_matrix4x4(*view_mat); 
}

c_matrix4x4 c_camera::get_proj() const
{
	const D3DXMATRIX *proj_mat = GetProjMatrix();
	return c_matrix4x4(*proj_mat); 
}

bool c_camera::update(c_scene *scene, const float dt)
{
    return true; 
}

void c_camera::render(c_scene *scene)
{
    
}

c_matrix4x4 c_camera::get_view_proj()
{
	return get_view() * get_proj(); 
}
